package com.tamtamy.jtta.data.json;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.tamtamy.jtta.data.UsersList;
import com.tamtamy.jtta.exception.NoResultException;

public class JSONUsersList extends UsersList {

	private static final long serialVersionUID = 6918631112256726305L;

	public JSONUsersList(JSONObject jsonObject) throws NoResultException{
		super();
		JSONArray usersListJSON = (JSONArray)jsonObject.get("list");
		if (usersListJSON == null || usersListJSON.size()==0){
			throw new NoResultException("No user stats found");
		}
		for (int i = 0; i < usersListJSON.size(); i++) {
			JSONObject usersSON = usersListJSON.getJSONObject(i);
			this.add(new JSONUser(usersSON));
		}	
		JSONObject paginationInfo = (JSONObject)jsonObject.get("paginationInfo");
		int total = paginationInfo.getInt("total");
		setTotal(total);
	}

}
